﻿using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraEditors.Repository;

// 简化的查询控件类型枚举
public enum SearchControlType
{
    TextBox,        // 文本框
    ComboBox,       // 下拉框
    DateEdit,       // 日期选择器
    CheckBox        // 复选框
}

public class DeviceGridPanel : UserControl
{
    // 上部按钮区
    public PanelControl panelTop;
    public SimpleButton btnAdd;
    public SimpleButton btnExport;
    public SimpleButton btnDelete;

    // 查询控件
    public PanelControl panelSearch;
    public SimpleButton btnSearch;
    public SimpleButton btnReset;

    // 中部表格
    public PanelControl panelMiddle;
    public GridControl gridControl;
    public GridView gridView;

    // 下部分页区
    public PanelControl panelBottom;
    public SimpleButton btnPrev;
    public SimpleButton btnNext;
    public LabelControl lblPageInfo;
    public ComboBoxEdit cmbPageSize; // 新增
    public SimpleButton btnFirst;
    public SimpleButton btnLast;

    // 分页属性
    public int PageIndex { get; private set; } = 1;
    public int PageSize { get; private set; } = 20;
    public int TotalCount { get; private set; } = 0;

    // 存储查询控件的字典
    private Dictionary<string, Control> searchControls = new Dictionary<string, Control>();

    // 事件
    public event EventHandler AddClicked;
    public event EventHandler ExportClicked;
    public event EventHandler DeleteClicked;
    public event EventHandler<string> EditClicked;
    public event Func<int, int, Task> OnPageChanged; // 页码、每页数量
    public event EventHandler SearchClicked; // 查询事件
    public event EventHandler ResetClicked; // 重置事件

    public DeviceGridPanel()
    {
        // 查询区域
        panelSearch = new PanelControl { Dock = DockStyle.Top, Height = 60 };
        panelSearch.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#3f2b96");
        panelSearch.Appearance.Options.UseBackColor = true;

        // 上部按钮区
        panelTop = new PanelControl { Dock = DockStyle.Top, Height = 80 };
        panelTop.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#3f2b96");
        panelTop.Appearance.Options.UseBackColor = true;

        // 创建FlowLayoutPanel
        FlowLayoutPanel flowPanel = new FlowLayoutPanel
        {
            Dock = DockStyle.Fill,
            RightToLeft = RightToLeft.Yes, // 关键点：让内容靠右
            FlowDirection = FlowDirection.LeftToRight,
            Padding = new Padding(10, 15, 10, 0), // 上边距15，左边距10
            AutoSize = true
        };


        btnAdd = new SimpleButton { Text = "新增", Left = 10, Top = 8, Margin = new Padding(0, 0, 10, 0) };
        btnExport = new SimpleButton { Text = "导出", Left = 90, Top = 8, Margin = new Padding(0, 0, 10, 0) };
        btnDelete = new SimpleButton { Text = "删除", Left = 170, Top = 8, Margin = new Padding(0, 0, 10, 0) };

        // 新增按钮
        btnAdd.Text = "新增";
        btnAdd.Width = 90;
        btnAdd.Height = 40;
        btnAdd.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#93c47d");
        btnAdd.Appearance.ForeColor = System.Drawing.Color.White;
        btnAdd.Appearance.Options.UseBackColor = true;
        btnAdd.Appearance.Options.UseForeColor = true;
        btnAdd.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
        btnAdd.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
        btnAdd.LookAndFeel.UseDefaultLookAndFeel = false;
        btnAdd.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular);
        btnAdd.Padding = new Padding(10, 5, 10, 5);
        btnAdd.AutoSize = false;

        // 导出按钮
        btnExport.Text = "导出";
        btnExport.Width = 90;
        btnExport.Height = 40;
        btnExport.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#6fa8dc"); 
        btnExport.Appearance.ForeColor = System.Drawing.Color.White;
        btnExport.Appearance.Options.UseBackColor = true;
        btnExport.Appearance.Options.UseForeColor = true;
        btnExport.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
        btnExport.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
        btnExport.LookAndFeel.UseDefaultLookAndFeel = false;
        btnExport.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular);
        btnExport.Padding = new Padding(10, 5, 10, 5);
        btnExport.AutoSize = false;

        // 删除按钮
        btnDelete.Text = "删除";
        btnDelete.Width = 90;
        btnDelete.Height = 40;
        btnDelete.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#e06666"); 
        btnDelete.Appearance.ForeColor = System.Drawing.Color.White;
        btnDelete.Appearance.Options.UseBackColor = true;
        btnDelete.Appearance.Options.UseForeColor = true;
        btnDelete.ButtonStyle = DevExpress.XtraEditors.Controls.BorderStyles.NoBorder;
        btnDelete.LookAndFeel.Style = DevExpress.LookAndFeel.LookAndFeelStyle.Flat;
        btnDelete.LookAndFeel.UseDefaultLookAndFeel = false;
        btnDelete.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Regular);
        btnDelete.Padding = new Padding(10, 5, 10, 5);
        btnDelete.AutoSize = false;

        // 添加到FlowLayoutPanel
        flowPanel.Controls.Add(btnDelete);
        flowPanel.Controls.Add(btnAdd);
        flowPanel.Controls.Add(btnExport);
        panelTop.Controls.Add(flowPanel);
        // panelTop.Controls.AddRange(new Control[] { btnAdd, btnExport, btnDelete });

        btnAdd.Click += (s, e) => AddClicked?.Invoke(this, EventArgs.Empty);
        btnExport.Click += (s, e) => ExportClicked?.Invoke(this, EventArgs.Empty);
        btnDelete.Click += (s, e) => DeleteClicked?.Invoke(this, EventArgs.Empty);

        // 中部表格
        panelMiddle = new PanelControl { Dock = DockStyle.Fill };
        panelMiddle.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        panelMiddle.Appearance.Options.UseBackColor = true;
        gridControl = new GridControl { Dock = DockStyle.Fill };
        gridView = new GridView();
        gridView.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None;
         gridView.OptionsView.ShowIndicator = false;
        gridControl.MainView = gridView;
        gridControl.ViewCollection.Add(gridView);

        // 设置表格背景色

        // 多选框
        gridView.OptionsSelection.MultiSelect = true;
        gridView.OptionsSelection.MultiSelectMode = GridMultiSelectMode.CheckBoxRowSelect;

        // 操作列
        AddEditColumn();

        panelMiddle.Controls.Add(gridControl);

        // 下部分页区
        panelBottom = new PanelControl { Dock = DockStyle.Bottom, Height = 70 };
        panelBottom.Appearance.BackColor = System.Drawing.ColorTranslator.FromHtml("#3f2b96");
        panelBottom.Appearance.Options.UseBackColor = true;

        // 创建FlowLayoutPanel
        FlowLayoutPanel flowPanel3 = new FlowLayoutPanel
        {
            Dock = DockStyle.Fill,
            FlowDirection = FlowDirection.LeftToRight,
            Padding = new Padding(10, 8, 0, 0), // 上下左右间距
            AutoSize = true,
            WrapContents = false // 横向排列
        };

        // 分页控件
        btnFirst = new SimpleButton { Text = "首页", Width = 70, Height = 30, Margin = new Padding(0, 0, 10, 0) };
        btnPrev = new SimpleButton { Text = "上一页", Width = 70, Height = 30, Margin = new Padding(0, 0, 10, 0) };
        btnNext = new SimpleButton { Text = "下一页", Width = 70, Height = 30, Margin = new Padding(10, 0, 0, 0) };
        btnLast = new SimpleButton { Text = "尾页", Width = 70, Height = 30, Margin = new Padding(10, 0, 0, 0) };

        LabelControl lblPageSize = new LabelControl { Text = "每页显示：", AutoSize = true, Margin = new Padding(0, 6, 0, 0) };
        cmbPageSize = new ComboBoxEdit
        {
            Width = 60,
            Properties = { TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor }
        };
        cmbPageSize.Properties.Items.AddRange(new object[] { 10, 20, 40, 80 });
        cmbPageSize.SelectedIndex = 1; // 默认20

        LabelControl lblData = new LabelControl { Text = "条", AutoSize = true, Margin = new Padding(0, 6, 0, 0) };
        lblPageInfo = new LabelControl { AutoSize = true, Margin = new Padding(10, 6, 0, 0) };

        // 添加到FlowLayoutPanel
        flowPanel3.Controls.Add(btnFirst);
        flowPanel3.Controls.Add(btnPrev);
        flowPanel3.Controls.Add(lblPageSize);
        flowPanel3.Controls.Add(cmbPageSize);
        flowPanel3.Controls.Add(lblData);
        flowPanel3.Controls.Add(btnNext);
        flowPanel3.Controls.Add(btnLast);
        flowPanel3.Controls.Add(lblPageInfo);

        // 添加FlowLayoutPanel到panelBottom
        panelBottom.Controls.Add(flowPanel3);

        // 分页控件事件绑定
        btnPrev.Click += (s, e) =>
        {
            if (PageIndex > 1)
            {
                ChangePage(PageIndex - 1);
            }
        };

        btnNext.Click += (s, e) =>
        {
            if (PageIndex < GetTotalPage())
            {
                ChangePage(PageIndex + 1);
            }
        };

        cmbPageSize.SelectedIndexChanged += (s, e) =>
        {
            int newSize = Convert.ToInt32(cmbPageSize.SelectedItem);
            if (PageSize != newSize)
            {
                PageSize = newSize;
                ChangePage(1); // 切换每页数量后回到第一页
            }
        };

        btnFirst.Click += (s, e) =>
        {
            if (PageIndex != 1)
            {
                ChangePage(1);
            }
        };

        btnLast.Click += (s, e) =>
        {
            int totalPage = GetTotalPage();
            if (PageIndex != totalPage)
            {
                ChangePage(totalPage);
            }
        };

        // 添加到主控件 - 注意顺序：查询区域在最上面
        Controls.Add(panelMiddle);
        Controls.Add(panelTop);
        Controls.Add(panelSearch);
        Controls.Add(panelBottom);

        // 表头样式
        gridView.Appearance.HeaderPanel.Font = new System.Drawing.Font("微软雅黑", 12F, System.Drawing.FontStyle.Bold);
        gridView.Appearance.HeaderPanel.Options.UseFont = true;
        gridView.Appearance.HeaderPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        gridView.Appearance.HeaderPanel.Options.UseBackColor = true;
        gridView.Appearance.HeaderPanel.ForeColor = System.Drawing.Color.Black; // 可选，表头字体颜色

        // 内容样式
        gridView.Appearance.Row.Font = new System.Drawing.Font("微软雅黑", 10F, System.Drawing.FontStyle.Regular);
        gridView.Appearance.Row.Options.UseFont = true;
        gridView.Appearance.Row.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        gridView.Appearance.Row.Options.UseBackColor = true;
        gridView.Appearance.Row.ForeColor = System.Drawing.Color.Black; // 可选，内容字体颜色

        gridView.Appearance.FocusedRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        gridView.Appearance.FocusedRow.Options.UseBackColor = true;

        gridView.Appearance.FocusedCell.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        gridView.Appearance.FocusedCell.Options.UseBackColor = true;

        gridView.Appearance.SelectedRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#8f94fb");
        gridView.Appearance.SelectedRow.Options.UseBackColor = true;

        // 禁止表头换行
        gridView.Appearance.HeaderPanel.TextOptions.WordWrap = DevExpress.Utils.WordWrap.NoWrap;

        // 允许横向滚动条（如果列太多）
        gridView.OptionsView.ColumnAutoWidth = false;

        // 自动适应表头和内容宽度
        gridView.BestFitColumns();

        int btnWidth = 100;
        int btnHeight = 35;
        int fontSize = 10;

        // 首页
        btnFirst.Width = btnWidth;
        btnFirst.Height = btnHeight;
        btnFirst.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        btnFirst.Margin = new Padding(8, 0, 8, 0);

        // 上一页
        btnPrev.Width = btnWidth;
        btnPrev.Height = btnHeight;
        btnPrev.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        btnPrev.Margin = new Padding(8, 0, 8, 0);

        // 下一页
        btnNext.Width = btnWidth;
        btnNext.Height = btnHeight;
        btnNext.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        btnNext.Margin = new Padding(8, 0, 8, 0);

        // 尾页
        btnLast.Width = btnWidth;
        btnLast.Height = btnHeight;
        btnLast.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        btnLast.Margin = new Padding(8, 0, 8, 0);

        // 下拉框
        cmbPageSize.Width = 70;
        cmbPageSize.Height = btnHeight;
        cmbPageSize.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        cmbPageSize.Margin = new Padding(8, 0, 8, 0);

        // 其他Label
        lblPageInfo.Font = new System.Drawing.Font("微软雅黑", fontSize, System.Drawing.FontStyle.Regular);
        lblPageInfo.Margin = new Padding(16, 0, 0, 0);

        // 分页区Label字体颜色加白色
        lblPageSize.Appearance.ForeColor = System.Drawing.Color.White;
        lblPageSize.Appearance.Options.UseForeColor = true;
        lblData.Appearance.ForeColor = System.Drawing.Color.White;
        lblData.Appearance.Options.UseForeColor = true;
        lblPageInfo.Appearance.ForeColor = System.Drawing.Color.White;
        lblPageInfo.Appearance.Options.UseForeColor = true;

        // 分页按钮字体颜色加白色
      //  btnFirst.Appearance.ForeColor = System.Drawing.Color.White;
        btnFirst.Appearance.Options.UseForeColor = true;
       // btnPrev.Appearance.ForeColor = System.Drawing.Color.White;
        btnPrev.Appearance.Options.UseForeColor = true;
       // btnNext.Appearance.ForeColor = System.Drawing.Color.White;
        btnNext.Appearance.Options.UseForeColor = true;
       // btnLast.Appearance.ForeColor = System.Drawing.Color.White;
        btnLast.Appearance.Options.UseForeColor = true;
    }

    // 简化的动态生成查询控件方法
    public void GenerateSearchControls(Dictionary<string, SearchControlType> fieldMappings, Dictionary<string, string> displayNames = null, Dictionary<string, List<string>> comboOptions = null)
    {
        // 清空现有的查询控件
        if (panelSearch != null)
        {
            panelSearch.Controls.Clear();
            searchControls.Clear();
        }

        // 创建查询区域的FlowLayoutPanel
        FlowLayoutPanel searchFlowPanel = new FlowLayoutPanel
        {
            Dock = DockStyle.Fill,
            FlowDirection = FlowDirection.LeftToRight,
            Padding = new Padding(10, 15, 10, 0),
            AutoSize = true
        };

        // 动态生成查询控件
        foreach (var field in fieldMappings)
        {
            string fieldName = field.Key;
            SearchControlType controlType = field.Value;
            string displayName = displayNames?.ContainsKey(fieldName) == true ? displayNames[fieldName] : fieldName;

            // 添加字段标签
            LabelControl lblField = new LabelControl
            {
                Text = $"{displayName}：",
                AutoSize = true,
                Margin = new Padding(0, 6, 0, 0)
            };
            lblField.Appearance.ForeColor = System.Drawing.Color.White;
            lblField.Appearance.Options.UseForeColor = true;
            searchFlowPanel.Controls.Add(lblField);

            // 根据字段类型创建不同的控件
            Control fieldControl = CreateSimpleFieldControl(fieldName, controlType, comboOptions?.ContainsKey(fieldName) == true ? comboOptions[fieldName] : null);
            searchFlowPanel.Controls.Add(fieldControl);

            // 存储控件引用
            searchControls[fieldName] = fieldControl;
        }

        // 添加查询和重置按钮
        btnSearch = new SimpleButton { Text = "查询", Width = 60, Height = 30, Margin = new Padding(10, 0, 0, 0) };
        btnReset = new SimpleButton { Text = "重置", Width = 60, Height = 30, Margin = new Padding(10, 0, 0, 0) };

       // btnSearch.Appearance.ForeColor = System.Drawing.Color.White;
        btnSearch.Appearance.Options.UseForeColor = true;
       // btnReset.Appearance.ForeColor = System.Drawing.Color.White;
        btnReset.Appearance.Options.UseForeColor = true;

        searchFlowPanel.Controls.Add(btnSearch);
        searchFlowPanel.Controls.Add(btnReset);

        // 绑定按钮事件
        btnSearch.Click += (s, e) => SearchClicked?.Invoke(this, EventArgs.Empty);
        btnReset.Click += (s, e) => ResetClicked?.Invoke(this, EventArgs.Empty);

        panelSearch.Controls.Add(searchFlowPanel);
    }

    // 简化的创建字段控件方法
    private Control CreateSimpleFieldControl(string fieldName, SearchControlType controlType, List<string> options = null)
    {
        switch (controlType)
        {
            case SearchControlType.TextBox:
                var textBox = new TextEdit
                {
                    Width = 150,
                    Margin = new Padding(0, 3, 10, 0),
                    Name = $"txt_{fieldName}"
                };
                return textBox;

            case SearchControlType.ComboBox:
                var comboBox = new ComboBoxEdit
                {
                    Width = 150,
                    Margin = new Padding(0, 3, 10, 0),
                    Name = $"cmb_{fieldName}",
                    Properties = { TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.DisableTextEditor }
                };
                if (options != null)
                {
                    comboBox.Properties.Items.AddRange(options.ToArray());
                }
                return comboBox;

            case SearchControlType.DateEdit:
                var dateEdit = new DateEdit
                {
                    Width = 150,
                    Margin = new Padding(0, 3, 10, 0),
                    Name = $"date_{fieldName}",
                    Properties = { DisplayFormat = { FormatString = "yyyy-MM-dd" } }
                };
                return dateEdit;

            case SearchControlType.CheckBox:
                var checkBox = new CheckEdit
                {
                    Width = 150,
                    Margin = new Padding(0, 3, 10, 0),
                    Name = $"chk_{fieldName}",
                    Text = fieldName
                };
                return checkBox;

            default:
                return new TextEdit { Width = 150, Margin = new Padding(0, 3, 10, 0) };
        }
    }

    // 简化的获取查询条件方法
    public Dictionary<string, object> GetSearchConditions()
    {
        var conditions = new Dictionary<string, object>();

        foreach (var kvp in searchControls)
        {
            string fieldName = kvp.Key;
            Control control = kvp.Value;

            if (control is TextEdit textBox && !string.IsNullOrEmpty(textBox.Text))
            {
                conditions[fieldName] = textBox.Text;
            }
            else if (control is ComboBoxEdit comboBox && comboBox.SelectedItem != null)
            {
                conditions[fieldName] = comboBox.SelectedItem.ToString();
            }
            else if (control is DateEdit dateEdit && dateEdit.DateTime != DateTime.MinValue)
            {
                conditions[fieldName] = dateEdit.DateTime;
            }
            else if (control is CheckEdit checkBox)
            {
                conditions[fieldName] = checkBox.Checked;
            }
        }

        return conditions;
    }

    // 简化的重置查询条件方法
    public void ResetSearchConditions()
    {
        foreach (var control in searchControls.Values)
        {
            if (control is TextEdit textBox)
            {
                textBox.Text = string.Empty;
            }
            else if (control is ComboBoxEdit comboBox)
            {
                comboBox.SelectedIndex = -1;
            }
            else if (control is DateEdit dateEdit)
            {
                dateEdit.DateTime = DateTime.MinValue;
            }
            else if (control is CheckEdit checkBox)
            {
                checkBox.Checked = false;
            }
        }
    }

    // 绑定数据
    public void SetDataSource<T>(List<T> data)
    {
        gridView.Columns.Clear(); // 清空所有列
        gridControl.DataSource = null;
        gridControl.DataSource = data;
        gridView.BestFitColumns();
        AddEditColumn(); // 确保操作列是最后添加的
    }

    // 添加操作列
    private void AddEditColumn()
    {
        if (gridView != null)
        {
            // 设置为鼠标按下即触发
            gridView.OptionsBehavior.EditorShowMode = DevExpress.Utils.EditorShowMode.MouseDown;

            // 创建按钮编辑器
            var buttonEdit = new DevExpress.XtraEditors.Repository.RepositoryItemButtonEdit();
            buttonEdit.Buttons[0].Caption = "编辑";
            buttonEdit.Buttons[0].Kind = DevExpress.XtraEditors.Controls.ButtonPredefines.Glyph;
            buttonEdit.TextEditStyle = DevExpress.XtraEditors.Controls.TextEditStyles.HideTextEditor;
            buttonEdit.ButtonClick += (s, e) =>
            {
                // 获取当前行的id
                var view = gridView;
                int rowHandle = view.FocusedRowHandle;
                if (rowHandle >= 0)
                {
                    var row = view.GetRow(rowHandle);
                    var idProp = row.GetType().GetProperty("Id");
                    if (idProp != null)
                    {
                        var id = idProp.GetValue(row);
                        EditClicked?.Invoke(this, Convert.ToString(id));
                    }
                }
            };

            // 创建操作列
            GridColumn colEdit = new GridColumn
            {
                Caption = "操作",
                Name = "colEdit",
                Visible = true,
                VisibleIndex = gridView.Columns.Count,
                ColumnEdit = buttonEdit,
                Width = 60
            };
            gridView.Columns.Add(colEdit);
            gridControl.RepositoryItems.Add(buttonEdit);
        }
    }

    // 设置分页信息
    public void SetPageInfo(int pageIndex, int pageSize, int totalCount)
    {
        PageIndex = pageIndex;
        PageSize = pageSize;
        TotalCount = totalCount;
        lblPageInfo.Text = $"第 {PageIndex} / {GetTotalPage()} 页，共 {TotalCount} 条";
        btnPrev.Enabled = PageIndex > 1;
        btnNext.Enabled = PageIndex < GetTotalPage();
    }

    private int GetTotalPage()
    {
        return (int)Math.Ceiling(TotalCount * 1.0 / PageSize);
    }

    private async void ChangePage(int newPage)
    {
        if (OnPageChanged != null)
        {
            await OnPageChanged(newPage, PageSize);
        }
    }

    // 获取选中行的所有Id，并用逗号拼接
    public string GetSelectedIdsString()
    {
        var selectedHandles = gridView.GetSelectedRows();
        List<string> ids = new List<string>();
        foreach (var handle in selectedHandles)
        {
            var row = gridView.GetRow(handle);
            var idProp = row?.GetType().GetProperty("Id");
            if (idProp != null)
            {
                var id = idProp.GetValue(row);
                if (id != null)
                    ids.Add(id.ToString());
            }
        }
        return string.Join(",", ids);
    }

    public void SetColumnCaptions(Dictionary<string, string> columnCaptions)
    {
        foreach (GridColumn col in gridView.Columns)
        {
            if (columnCaptions.ContainsKey(col.FieldName))
            {
                col.Caption = columnCaptions[col.FieldName];
            }
        }
    }

}